package com.game.fighting.component;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.component.Component;
import com.almasb.fxgl.texture.AnimatedTexture;
import com.almasb.fxgl.texture.AnimationChannel;
import javafx.scene.layout.HBox;
import javafx.util.Duration;

/**
 * @author LeeWyatt
 */
public class ScoreComponent extends Component {

    @Override
    public void onAdded() {
        //area
        String area = entity.getString("area");
        int score;
        if ("high".equals(area)) {
            score = 20;
        } else if ("middle".equals(area)) {
            score = 8;
        } else {
            score = 1;
        }
        String[] ss = String.valueOf(score).split("");
        HBox box = new HBox();
        for (int i = 0; i < ss.length; i++) {
            AnimatedTexture texture = new AnimatedTexture(
                    new AnimationChannel(
                            FXGL.image("score/" + area + ".png")
                            , 10, 22, 28,
                            Duration.ZERO, Integer.parseInt(ss[i]), Integer.parseInt(ss[i]))
            );
            box.getChildren().add(texture);
        }
        box.setScaleX(1.5);
        box.setScaleY(1.5);
        entity.getViewComponent().addChild(box);

    }
}

